<?php
declare (strict_types=1);

namespace app\common\model;

use think\Collection;

class AdPosition extends CommonBase
{

    public function getAllAdPosition(array $where = []): Collection
    {
        $where['is_delete'] = config('status.mysql.table_normal');
        return $this->where($where)->select();
    }

    public function getAdPositionList(int $page = 1, int $limit = 10, array $where = []): Collection
    {
        $where['is_delete'] = config('status.mysql.table_normal');
        $offset             = ($page - 1) * $limit;
        return $this->where($where)->limit($offset, $limit)->select();
    }

    public function getAdPositionCount(array $where = []): int
    {
        $where['is_delete'] = config('status.mysql.table_normal');
        return $this->where($where)->count();
    }

    public function findAdPositionById(int $id)
    {
        return $this->where(['id' => $id, 'is_delete' => config('status.mysql.table_normal')])->find();
    }

    public function addAdPosition(array $data): bool
    {
        $data['is_delete'] = config('status.mysql.table_normal');
        return (boolean)$this->save($data);
    }

    public function updateAdPosition(int $id, array $data): bool
    {
        $data['updated_at'] = date('Y-m-d H:i:s');
        return (boolean)$this->where(['id' => $id])->save($data);
    }

    public function deleteAdPosition(int $id): bool
    {
        return (boolean)$this->where(['id' => $id])->save(['is_delete' => config('status.mysql.table_delete')]);
    }
}
